using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LeisureCenter.Core;
using LeisureCenter.Forms;
using LeisureCenter.Controls;

namespace LeisureCenter.OptionsForms
{
    public partial class LibraryOptionsDialog : LeisureCenter.Forms.DialogControl
    {
        public LibraryOptionsDialog()
        {
            InitializeComponent();
        }

        private long libraryId;

        public long LibraryId
        {
            get { return libraryId; }
            set
            {
                libraryId = value;
                btnName.Text = DatabaseManager.ExecuteStringScalar(@"SELECT name FROM Libraries WHERE id = " + libraryId, @"<<none>>");
            }
        }

        private void btnName_Click(object sender, EventArgs e)
        {
            string name = "";
            if (VirtualKeyboardDialog.Execute(string.Format(@"Enter '{0}' new name:", btnName.Text), ref name) && !string.IsNullOrEmpty(name))
            {
                DatabaseManager.ExecuteNonQuery(string.Format(@"UPDATE Libraries SET name = '{0}' WHERE id = {1}", name, this.libraryId));
                btnName.Text = name;
            }
        }

        public override void SetFocusHandlers(LeisureCenter.Api.IFocusHandler okButton, LeisureCenter.Api.IFocusHandler cancelButton)
        {
            btnName.FocusDown = okButton;
        }
    }
}
